﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace BDH.BLL
{
    public class ThanhvienBLL : DAL.ThanhvienDAL
    {
        public string EncodeMD5(string inputString)
        {
            MD5 md5 = MD5.Create();
            byte[] data = md5.ComputeHash(Encoding.UTF8.GetBytes(inputString));
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < data.Length; i++)
                sb.Append(data[i].ToString("x2"));

            return sb.ToString();
        }

        public UTL.Session CheckLogin(string user, string pass)
        {
            //string mk = EncodeMD5(pass);
            var usr = (DAL.Entities.Thanhvien)GetByKey(user);
            var sss = new UTL.Session();

            if (usr != null)
            {
                sss.Login = usr.matkhau == pass ? true : false;
                sss.Acc = usr.taikhoan;
                sss.Pass = usr.matkhau;
                sss.Name = usr.hoten;
                sss.Role = usr.vaitro;
            }
            else
                sss.Login = false;

            return sss;
        }

    }
}
